package com.myapplication.ui.listfragment.shoplistactivity;

import com.myapplication.bean.ShopListBean;
import com.myapplication.config.HUrlConfig;
import com.myapplication.http.RetrofitService;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by zitaojiang on 2016/10/6.
 */
public class Model_ShopList implements Contract_ShopList.Model{
    @Override
    public void getData(final String type, final Map<String, String> params, final SendShopListListener sendShopListListener) {
//        HttpUtils.getSingletion().getShopListData(HUrlConfig.Path.SHOPLIST_BASEURL,type,params,callback);
        new Thread(new Runnable() {
            @Override
            public void run() {
                Retrofit retrofit=new Retrofit.Builder()
                        .baseUrl(HUrlConfig.Path.SHOPLIST_BASEURL)
                        .addConverterFactory(GsonConverterFactory.create())
                        .build();
                Call<ShopListBean> call=retrofit.create(RetrofitService.class).getShopListData(type,params);
                call.enqueue(new Callback<ShopListBean>() {
                    @Override
                    public void onResponse(Call<ShopListBean> call, Response<ShopListBean> response) {
                        List<ShopListBean.DataBean.ItemsBean> itemsBeanList=response.body().getData().getItems();
                        sendShopListListener.sendShopList(itemsBeanList);
                    }

                    @Override
                    public void onFailure(Call<ShopListBean> call, Throwable t) {

                    }
                });
            }
        }).start();
    }
    public interface SendShopListListener{
        void sendShopList(List<ShopListBean.DataBean.ItemsBean> itemsBeanList);
    }

}
